﻿@{
    ViewBag.Title = "AddGoods";
    Layout = "~/Views/Shared/_Layout_User.cshtml";
    var CurrentUser = ViewBag.LoginUser as BabyPlan.mvcApp.ViewModel.UserModel;
    ResourceHelper.RegisterCss(this, "user.profile.css");
}
@section Js_InHeader{
@*<style type="text/css">
    .right_block_title{height:50px;}
    .right_block_title .title{line-height:50px;}
    .profile_input_outer{display:inline-block;padding:20px 0;}
    .profile_input_item{width:620px;margin:10px 40px;display:inline-block;}
    .profile_input_item > dt{float:left;width:100px;line-height:30px;text-align:right;}
    .profile_input_item > dd{float:left;}
    .profile_input_item .profile_head_box{width:100px;height:100px;border:solid 1px #ddd;}
    .profile_input_item .upload_btn_box{width:120px;height:30px;}
    .profile_input_item .upload_head_btn{width:120px;height:30px;padding:0;}
    
    .submit_btn{padding:0;width:120px;height:40px;line-height:40px;margin:10px auto; font-weight:normal;}

</style>*@
}

<div class="right_block_title user_right_block grayblock">
    <span class="title margin10 font-size16 black-font">账户设置</span>
</div>
<div class="profile_input_outer user_right_block whiteblock">
    <dl class="profile_input_item">
        <dt class="font-size16 black-font">头像设置：&nbsp;&nbsp;<span class="white-font" name="errortag">*</span></dt>
        <dd>
            <dl>
                <dt class="fl profile_head_box" name="head_pic_box">
                @if (CurrentUser.HeadPic != null)
                {
                    CurrentUser.HeadPic.DisplaySeting(100, 100);
                <img name='pic' src="@CurrentUser.HeadPic.PicUrl" style="width:@CurrentUser.HeadPic.DisWidth.ToString()px;height;@CurrentUser.HeadPic.DisHeight.ToString()px;margin:@CurrentUser.HeadPic.DisMargin;" />
                }
                else
                { 
                <img name='pic' src="@Content.SourceSrc("tx.png", Url, BabyPlan.mvcApp.Infras.SourceRootEnums.Images)" style="width:100px;height;100px;" />
                }
                </dt>
                <dd class="fl" style="margin:0 20px;">
                    <div class="upload_btn_box" id="profile_upload_head_box">
                        <a href="javascript:void(0)" class="button-blue">修改头像</a>
                    </div>
                    <span class="gray-font">仅支持jpg、gif、png格式， 文件小于2M</span>
                </dd>
            </dl>
        </dd>
    </dl>
    <form id="profile_form" action="@Url.Action("AjaxProfile", "User")" method="post">
    <dl class="profile_input_item">
        <dt class="font-size16 black-font">用户名：&nbsp;&nbsp;<span class="white-font" name="errortag">*</span></dt>
        <dd>
            <input type="text" class="input_box" id="u_account" name="u_account" value="@CurrentUser.Account" readonly="readonly" style="width:460px;" />
        </dd>
    </dl>
    <dl class="profile_input_item">
        <dt class="font-size16 black-font"> 性别：&nbsp;&nbsp;<span  class="white-font" name="errortag">*</span></dt>
        <dd class="font-size16 black-font">
            <input name="u_sex" type="radio" @Html.Raw(CurrentUser.CheckedBind(CurrentUser.Sex, 1))  @Html.Raw(CurrentUser.CheckedBind(CurrentUser.Sex, 0)) value="1" />男
            <input name="u_sex" type="radio" @Html.Raw(CurrentUser.CheckedBind(CurrentUser.Sex, 2)) value="2" />女
        </dd>
    </dl>
    <dl class="profile_input_item">
        <dt class="font-size16 black-font">当前密码：&nbsp;&nbsp;<span class="white-font" name="errortag">*</span></dt>
        <dd>
            <input type="password" class="input_box" id="u_old_password" name="u_old_password" value="" style="width:460px;" />
        </dd>
    </dl>
    <dl class="profile_input_item">
        <dt class="font-size16 black-font">新密码：&nbsp;&nbsp;<span class="white-font" name="errortag">*</span></dt>
        <dd>
            <input type="password" class="input_box" id="u_new_password" name="u_new_password" value="" style="width:460px;" />
        </dd>
    </dl>
    <dl class="profile_input_item">
        <dt class="font-size16 black-font">确认密码：&nbsp;&nbsp;<span class="white-font" name="errortag">*</span></dt>
        <dd>
            <input type="password" class="input_box" id="u_password_confirm" value="" style="width:460px;" />
        </dd>
    </dl>
    <input type="submit" id="submit_btn" class="button-green submit_btn font-size18" value="保 存" style="border:none;" />
    </form>
</div>
@section Js_InFoot{
 @Content.Script("cvalid.js", Url)
    @Content.Css("fancybox/jquery.fancybox-1.3.4.css", Url, BabyPlan.mvcApp.Infras.SourceRootEnums.JsLib)  
    @Content.Script("fancybox/jquery.fancybox-1.3.4.js", Url)
    @Content.Script("fancybox.msgbox.js", Url)
<script type="text/javascript">
    $(document).ready(function () {
        var timer;
        var picbox = $("[name='head_pic_box']");
        $("#profile_upload_head_box").cUpload({
            size: { width: 100, height: 100 },
            url: '@Url.Action("Uploader", "Upload")?type=h',
            loadingbox: picbox,
            uploaded: function (response) {
                if (!response.Saved) {
                    $.showMsg(response.Msg,"error");
                }
                else {
                    picbox.each(function () {
                        var picitem = $(this).find("img[name='pic']")
                        if (picitem.length == 0) {
                            picitem = $("<img name='pic' />");
                            picbox.append(picitem);
                        }
                        picitem.attr("src", response.Pic.PicUrl);
                        picitem.css({ 'width': response.Pic.DisWidth + "px", 'height': response.Pic.DisHeight + "px", margin: response.Pic.DisMargin });
                    });
                }
            }
        });

        var options = {
            dataType: 'json',
            beforeSubmit: beforeSubmit,
            success: submitSuccess
        };
        $("#profile_form").ajaxForm(options);

        function beforeSubmit() {
            var opChk = PasswordChk();
            var pwChk = NewPasswordChk();
            var cpChk = ConfrimPasswordChk();
            if (!opChk.pass) {
                opChk.elt.focus();
                return false;
            }
            if (!pwChk.pass) {
                pwChk.elt.focus();
                return false;
            }
            if (!cpChk.pass) {
                cpChk.elt.focus();
                return false;
            }
            $("#submit_btn").val("保存中...").attr("disabled", "false");
            return true;
        }

        function submitSuccess(response) {
            $("#submit_btn").val("保存").attr("disabled", "");
            if (response.Error == 0) {
                $.showMsg(response.ExMessage || "保存成功！", "success");
            } else {
                $.showMsg(response.ExMessage,"error");
            }
        }

        function PasswordChk() {
            var me = $("#u_old_password");
            var val = me.val();
            if (val.length >= 4 && val.length <= 16) {
                me.css("border", "solid 2px #8CBF26");
                return { pass: true, elt: me };
            }
            else {
                me.css("border", "solid 2px #f00");
                return { pass: false, elt: me };
            }
        }

        function NewPasswordChk() {
            var me = $("#u_new_password");
            var val = me.val();
            if (val.length >= 4 && val.length <= 16) {
                me.css("border", "solid 2px #8CBF26");
                return { pass: true, elt: me };
            }
            else {
                me.css("border", "solid 2px #f00");
                return { pass: false, elt: me };
            }
        }

        function ConfrimPasswordChk() {
            var me = $("#u_password_confirm");
            var val = me.val();
            var password = $("#u_new_password");
            var passwordval = password.val();
            if (val == passwordval) {
                me.css("border", "solid 2px #8CBF26");
                return { pass: true, elt: me };
            }
            else {
                me.css("border", "solid 2px #f00");
                return { pass: false, elt: me };
            }
        }
    });
</script>
}